<template>
	<view>

		<!-- 设置工资弹窗 -->
		<u-popup v-model="setShow" mode="bottom" border-radius="20" duration="0" :mask-close-able="false" closeable close-icon-size="40"
			safe-area-inset-bottom @close="setClose">
			<form @submit="formSubmit">
				<view class="setWrap_box">
					<view class="setHead_con" @click="setClose">
						<view class="setTit">工资设置</view>
					</view>
					<view class="handleList_box">
						<view class="handleList_con">
							<view class="handleLabel handleLabelLong">上班工资：</view>
							<view class="handleList">
								<view class="pickerCon">
									<input type="digit" name="salary" v-model="formData.salary" placeholder="请输入上班工资"
										placeholder-class="placeholderColor">
									<text>元/工</text>
								</view>
							</view>
						</view>
						<view class="handleList_con">
							<view class="handleLabel handleLabelLong">加班工资：</view>
							<view class="handleList">
								<view class="pickerCon">
									<input type="digit" name="overtime_salary" v-model="formData.overtime_salary"
										placeholder="请输入加班工资" placeholder-class="placeholderColor">
									<text>元/小时</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="handlePost_con">
					<button class="completeBtn" form-type="submit" hover-class="none">确 认</button>
				</view>
			</form>
		</u-popup>

		<!-- 确认弹窗 -->
		<u-popup v-model="confirmShow" mode="center" width="680" border-radius="30" duration="0" safe-area-inset-bottom>
			<!-- <view class="confirmChange_box">
				<view class="confirmChange_con">
					<view class="changeItem changeItem_before">
						<view class="changeHead">更改前</view>
						<view class="changeBody">
							<view class="money">{{salaryBefore}}</view>
							<view class="unit">元/工</view>
						</view>
					</view>

					<view class="changeItem changeItem_after">
						<view class="changeHead">更改后</view>
						<view class="changeBody">
							<view class="money">{{salary}}</view>
							<view class="unit">元/小时</view>
						</view>
					</view>
				</view>
				<view class="confirmNow" @click="submitSet(1)">从今天起生效</view>
				<view class="confirmBefore" @click="submitSet(2)">以前的也生效</view>
			</view> -->

			<view class="updateBox">
				<view class="updateHead_con">
					<view class="updateTitleItem updateTitleItemLeft">
						更改前
					</view>
					<view class="updateTitleItem updateTitleItemRight">
						更改后
					</view>
					<view class="toAfterIcon">
						<image src="/static/worker/changeIcon.png" mode=""></image>
					</view>
				</view>

				<view class="updateMain">
					<view class="updateMainItem">
						<text class="tit">上班工资(前)</text>
						<text class="moeny">{{salaryBefore}}元/工</text>
					</view>
					<view class="updateMainItem updateMainItemAfter">
						<text class="tit">上班工资(后)</text>
						<text class="moeny">{{formData.salary}}元/工</text>
					</view>
					<view class="updateMainItem">
						<text class="tit">加班工资(前)</text>
						<text class="moeny">{{overSalaryBefore}}元/工</text>
					</view>
					<view class="updateMainItem updateMainItemAfter">
						<text class="tit">加班工资(后)</text>
						<text class="moeny">{{formData.overtime_salary}}元/时</text>
					</view>
				</view>

				<view class="btnKongBox btnKongBoxActive" @click="submitSet(1)">
					从今天起生效
				</view>
				<view class="btnKongBox" @click="submitSet(2)">
					以前的也生效
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	export default {
		props: {
			// 选中的工人ids
			workerIds: {
				type: String,
				default: '0'
			},
			// 编辑
			edit: {
				type: Boolean,
				default: null
			},
			// 更改前
			salaryBefore: {
				type: String,
				default: '0'
			},
			overSalaryBefore: {
				type: String,
				default: '0'
			}
		},
		data() {
			return {
				// 设定弹窗
				setShow: false,

				// 确认弹窗
				confirmShow: false,

				// 工资表单
				formData: {
					salary: '',
					overtime_salary: '',
				},
			};
		},

		methods: {
			//清空数据
			clearData() {
				console.log('开始执行数据清空')
				var _this = this;
				_this.formData = {
					salary: '',
					overtime_salary: '',
				}

				_this.$forceUpdate();
			},

			updateData() {
				console.log('==工资弹出框==')
				console.log(this.salaryBefore)
				if (this.salaryBefore != 0) {
					this.salary = this.salaryBefore;
					this.formData.salary= this.salaryBefore;
				}
				if (this.overSalaryBefore != 0) {
					this.overtime_salary = this.overSalaryBefore;
					this.formData.overtime_salary= this.overSalaryBefore;
				}
			},

			// 提交
			formSubmit(e) {
				// console.log(e);
				var _this = this;
				var formData = e.detail.value;

				if (!formData.salary) {
					uni.showModal({
						content: '姓名不能为空',
						showCancel: false,
					})
					return;
				}

				// if (!formData.salary) {
				// 	uni.showModal({
				// 		content: '工资不能为空',
				// 		showCancel: false,
				// 	})
				// 	return;
				// }

				_this.formData = formData;
				_this.confirmShow = true;
			},

			// 提交设定工资
			submitSet(type) {
				console.log(type);
				var _this = this;
				uni.showToast({
					title: '数据处理中，请耐心等待',
					duration: 2000,
					icon:'none'
				});
				return
				_this.$u.post('/api/project.member/setSalary', {
					member_id: _this.workerIds,
					salary: _this.formData.salary,
					overtime_salary: _this.formData.overtime_salary,
					type: type,
				}).then(res => {
					console.log(res);

					// 编辑工资
					if (_this.edit) {
						_this.$parent.getRecordDetail();
					}

					uni.showToast({
						title: res.msg,
						duration: 2000
					});
					setTimeout(function() {
						_this.confirmShow = false;
						_this.setShow = false;
						_this.$parent.getWorkerList();
					}, 2000)
				}).catch(res => {
					console.log(res);
				})
			},

			// 关闭设定弹窗
			setClose() {
				this.setShow = false;
			},

		},
	}
</script>

<style scoped lang="scss">
	/* 设置工资弹窗 */
	.setWrap_box {
		padding: 0 30rpx;
	}

	.setHead_con {
		padding: 30rpx 0;
		overflow: hidden;
	}

	.setTit {
		width: 100%;
		font-size: 32rpx;
		font-weight: bold;
		color: $uni-color;
		text-align: center;
	}

	.handleList_box {
		padding: 15rpx 0;
	}

	/* 确认弹窗 */
	.confirmChange_box {
		padding: 30rpx;
		overflow: hidden;
	}

	.confirmChange_con {
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.changeItem {
		width: 300rpx;
		border-radius: 30rpx;
		overflow: hidden;

	}

	.changeHead {
		height: 86rpx;
		line-height: 86rpx;
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
		color: #000;
	}

	.changeBody {
		height: 160rpx;
		text-align: center;
		display: flex;
		flex-wrap: wrap;
		align-content: center;
	}

	.changeItem.changeItem_before .changeHead {
		background-color: #83C5FF;
	}

	.changeItem.changeItem_before .changeBody {
		background-color: #ecf6ff;
	}

	.changeItem.changeItem_after .changeHead {
		background-color: #FF9654;
	}

	.changeItem.changeItem_after .changeBody {
		background-color: #FFDFCB;
	}

	.money {
		width: 100%;
		font-size: 40rpx;
		font-weight: bold;
		color: #000;
	}

	.unit {
		width: 100%;
		font-size: 30rpx;
		color: #666;
		margin-top: 10rpx;
	}

	.confirmNow {
		width: 100%;
		height: 120rpx;
		line-height: 120rpx;
		text-align: center;
		font-size: 40rpx;
		font-weight: bold;
		color: #fff;
		background: $uni-color-primary;
		border-radius: 20rpx;
		overflow: hidden;
		margin: 40rpx 0;
	}

	.confirmBefore {
		width: 100%;
		height: 120rpx;
		line-height: 120rpx;
		text-align: center;
		font-size: 40rpx;
		font-weight: bold;
		color: $uni-color-primary;
		background: #fff;
		border: 2rpx solid $uni-color-primary;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.updateBox {
		padding: 30rpx;
	}

	.updateHead_con {
		width: 100%;
		height: 90rpx;
		position: relative;
	}

	.updateTitleItem {
		float: left;
		width: 310rpx;
		line-height: 90rpx;
		text-align: center;
		color: $uni-color-white;
	}

	.updateTitleItemLeft {
		border-radius: 20rpx 0 0 0;
		background-color: #7392BE;
		clip-path: polygon(0 0, 100% 0, 95% 100%, 0% 100%);
	}

	.updateTitleItemRight {
		background-color: #FC7032;
		border-radius: 0 20rpx 0 0;
		clip-path: polygon(5% 0, 100% 0, 100% 100%, 0% 100%);
	}

	.toAfterIcon {
		width: 40rpx;
		height: 40rpx;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}

	.toAfterIcon image {
		width: 100%;
		height: 100%;
	}

	.updateMain {
		width: 100%;
		height: 350rpx;
		border-radius: 0 0 20rpx 20rpx;
		background-color: #EBF1FF;
	}

	.updateMainItem {
		width: 40%;
		float: left;
		margin: 30rpx 5% 0 5%;
		text-align: center;
		font-size: 32rpx;
		line-height: 50rpx;
		color: $uni-color-text;
		border-bottom: 2rpx solid #fff;
		padding-bottom: 30rpx;

	}

	.updateMainItem .tit {
		display: block;
		font-size: 26rpx;
		color: $uni-color-text;
	}

	.updateMainItemAfter .moeny {
		color: #FC7032;
	}

	.btnKongBox {
		width: 630rpx;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 28rpx;
		font-weight: bold;
		margin: 30rpx auto 0 auto;
		border-radius: 10rpx;
		border: 2rpx solid $uni-color-text;
		text-align: center;
		box-sizing: $uni-color-text;
		overflow: hidden;
	}

	.btnKongBoxActive {
		border: 0;
		color: $uni-color-white;
		background-color: $uni-color-active;
	}
</style>
